package com.itheima.dao;

import com.itheima.pojo.Menu;
import com.github.pagehelper.Page;
import com.itheima.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;
import java.util.List;

public interface UserDao {
    public User findByUsername(String username);

    /**
     * 分页查询用户
     *
     * @param queryString
     * @return
     */
    @Select("select * from t_user where username like #{queryString}")
    Page<User> pageQuery(String queryString);

    /**
     * 查询用户
     *
     * @param username
     * @return
     */
    List<Menu> findMenuByUsername(String username);

    /**
     * 添加用户
     *
     * @param user
     */
    @Insert("insert into t_user values(null,#{birthday},#{gender},#{username},#{password},#{remark},#{station},#{telephone})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void add(User user);

    @Insert("insert into t_user_role values(#{user_id},#{role_id})")
    void addUserRoleIds(HashMap<String, Integer> idMap);
}
